//
//  LGVisaViewController.swift
//  01-Weibo项目练习-1
//
//  Created by 李李刚 on 16/3/7.
//  Copyright © 2016年 李李刚. All rights reserved.
//

import UIKit

class LGVisaViewController: UITableViewController ,LGBaseViewDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

            }
    
    //抽取一个视图
    lazy var baseView: LGBaseView = {
    
        let vc = LGBaseView()
        
//        vc.backgroundColor = UIColor.redColor()
        return vc
    }()
    
    
    var isLogon = false
    

    override func loadView() {
        
        if isLogon{
            
            super.loadView()
            
            
            
            
        }else{
            
            setupNoLogon()
            
        }
        
        
    }
    
    
    func setupNoLogon(){
        
        view = baseView
        
        baseView.delegate = self
        
//        baseView.backgroundColor = UIColor(red: 237/255, green: 237/255, blue: 237/255, alpha: 1)
        
//        baseView.backgroundColor = UIColor.redColor()
        
        
        
        //设置左右登录按钮
        
        self.navigationItem.rightBarButtonItem = UIBarButtonItem( title: "登录", target: self, action: "login")
        
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(imageName: nil, title: "注册", target: self, action: "loginSave")
    }
    
    @objc private func login(){
        
        print("登录点击")
        
        setupWeiboLogon()
        
    }
    
    lazy var web: UIWebView = {
       
        let w = UIWebView()
        
        return w
    }()
    
    func setupWeiboLogon(){
        
        let vc = LGOAuthViewController()
        
        presentViewController(UINavigationController(rootViewController: vc), animated: true, completion: nil)
        
        
        
        
    }
    
    
    
   @objc private func loginSave(){
        
        print("注册点击")
        
    }
    
    
    //实现代理方法
    
    func buttonDidClickView(baseView: LGBaseView, ClickButton: UIButton) {
        
        let str:String = (ClickButton.titleLabel?.text)!
        
        if str == "登录" {
            
            login()
        }else if str == "注册" {
            
            loginSave()
        }
            
            
        
        
    }
   


}
